// FallenPlugin.h (c) 2011 JV Software
//

#define SYS_API
#define _CRT_SECURE_NO_WARNINGS

#include <string>
#include <vector>

#include <maya/MGlobal.h>
//#include <maya/MSimple.h>
#include <maya/MPxCommand.h>
#include <maya/M3dView.h>

void Maya_RegisterPlugin( MString name, void* (*creator)() );
void Maya_DeregisterCommand( MString name );
HMODULE GetLocalModuleHandle( void );

#ifdef MAYA_PLUGIN_MAIN
#define DeclareSimpleCommand( _className, _vendor, _version )	\
class _className : public MPxCommand {							\
public:															\
					_className() {Maya_RegisterPlugin( #_className,					\
	                                _className::creator );};							\
									~_className() {Maya_DeregisterCommand( #_className ); }; \
	virtual MStatus	doIt ( const MArgList& );					\
	virtual MStatus   	redoIt( const MArgList &a ) { return doIt( a );  }			\
	static void*	creator();									\
};																\
void* _className::creator()										\
{																\
	return new _className;										\
}					
#else
#define DeclareSimpleCommand( _className, _vendor, _version )	\
class _className : public MPxCommand {							\
public:															\
					_className();						\
									~_className(); \
	virtual MStatus	doIt ( const MArgList& );					\
	static void*	creator();									\
};																
#endif

using namespace std;



#include "../../engine/inc/fstring.h"
#include "../../engine/inc/farray.h"
#include "../../engine/inc/ftexturefile.h"
#include "pluginMenu.h"
#include "pluginDialog.h"
#include "resource.h"
#include "FImageDialog.h"

/*
=============
M_OpenFileDialog
=============
*/

__forceinline string M_OpenFileDialog(char *filter = "All Files (*.*)\0*.*\0", HWND owner = NULL) {
  OPENFILENAMEA ofn;
  char fileName[MAX_PATH] = "";
  ZeroMemory(&ofn, sizeof(ofn));
 
  ofn.lStructSize = sizeof(OPENFILENAME);
  ofn.hwndOwner = owner;
  ofn.lpstrFilter = filter;
  ofn.lpstrFile = fileName;
  ofn.nMaxFile = MAX_PATH;
  ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
  ofn.lpstrDefExt = "";
 
  string fileNameStr;
 
  if ( GetOpenFileNameA(&ofn) )
    fileNameStr = fileName;
 
  return fileNameStr;
}

/*
============
M_SaveFileDialog
============
*/
__forceinline string M_SaveFileDialog(char *filter = "All Files (*.*)\0*.*\0", HWND owner = NULL) {
  OPENFILENAMEA ofn;
  char fileName[MAX_PATH] = "";
  ZeroMemory(&ofn, sizeof(ofn));
 
  ofn.lStructSize = sizeof(OPENFILENAME);
  ofn.hwndOwner = owner;
  ofn.lpstrFilter = filter;
  ofn.lpstrFile = fileName;
  ofn.nMaxFile = MAX_PATH;
  ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
  ofn.lpstrDefExt = "";
 
  string fileNameStr;
 
  if ( GetSaveFileNameA(&ofn) )
    fileNameStr = fileName;
 
  return fileNameStr;
}

//
// Plugin Commands
//
DeclareSimpleCommand( FImageDialogCmd, "", "7.0");

extern FImageDialogCmd			*imageDialogCmd;